package com.zerdoor.filter;

/**
 * Created by xiaobo on 2014/9/1.
 */

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestFilter implements Filter {

    // 创建线程
    public static ThreadLocal<HttpServletRequest> threadLocal = new ThreadLocal<HttpServletRequest>();

    public static final String SESSION_DATE = "appliedDate";

    public void destroy() {
        // TODO Auto-generated method stub

    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                         FilterChain arg2) throws IOException, ServletException {
        threadLocal.set((HttpServletRequest) arg0);
        HttpServletResponse response = ((HttpServletResponse) arg1);
        response.addHeader("Cache-Control", "no-cache");
        response.addHeader("Pragma", "No-cache");
        response.addDateHeader("Expires", 0);
//        HttpServletRequest req = (HttpServletRequest) arg0;
//        String currentUrl = req.getRequestURI();
//
//        if (currentUrl != null && !"".equals(currentUrl)) {
//                req.getSession().setAttribute(currentUrl, currentUrl);
//        }
        arg2.doFilter(arg0, arg1);
    }

    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub

    }

}

